package com.pro.service.imple;

import com.pro.mapper.CommentMapper;
import com.pro.pojo.JsComment;
import com.pro.pojo.JsMicrocircle;
import com.pro.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @ClassName: CommentController
 * @Author: Kai
 * @DATE: 2022/2/3
 * @TIME: 下午 01:46
 */
@Service
public class CommentServiceImple implements CommentService {
    @Autowired
    private CommentMapper commentMapper;

    /* 功能描述: <br>
     * 〈查看评论数量〉
     *
     * @param jsComment
     * @return: java.lang.Integer
     * @Author: Kai
     * @Date: 2022/2/3 下午 03:21
     */
    @Override
    public List<Map<String, Object>> getCountComment(JsComment jsComment) {
        List<Map<String, Object>> countComment = commentMapper.getCountComment(jsComment);
        return countComment;
    }

    /* 功能描述: <br>
     * 〈查看全部评论内容〉
     *
     * @param jsComment
     * @return: java.util.List<com.pro.pojo.JsComment>
     * @Author: Kai
     * @Date: 2022/2/16 下午 03:40
     */
    @Override
    public List<JsComment> getAllComments(JsComment jsComment) {
        if ("1".equals(jsComment.getUserType())){
            jsComment.setUserTable("js_before_user");
            jsComment.setUserName("nickname");
        }else if("2".equals(jsComment.getUserType())){
            jsComment.setUserTable("js_user");
            jsComment.setUserName("true_name");
        }
        if (jsComment.getType() == 2){
            jsComment.setTypeTable("js_course");
            jsComment.setTypeId("course_id");
            jsComment.setTypeName("course_name");
        }else if (jsComment.getType() == 3){
            jsComment.setTypeTable("js_product");
            jsComment.setTypeId("product_id");
            jsComment.setTypeName("product_name");
        }else if (jsComment.getType() == 4){
            jsComment.setTypeTable("js_microcircle");
            jsComment.setTypeId("microcircle_id");
            jsComment.setTypeName("artcle_title");
        }
        List<JsComment> allComments = commentMapper.getAllComments(jsComment);
        return allComments;
    }

    /* 功能描述: <br>
     * 〈修改评论信息〉
     *
     * @param jsComment
     * @return: java.lang.Boolean
     * @Author: Kai
     * @Date: 2022/2/17 上午 08:33
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Boolean updateComment(JsComment jsComment) throws Exception {
        if (jsComment.getId() == null || jsComment.getId() < 1) {
            throw new Exception("id不正确");
        }
        Boolean updateComment = commentMapper.updateComment(jsComment);
        return updateComment;
    }

    /* 功能描述: <br>
     * 〈查看所有评论内容〉
     *
     * @param
     * @return: java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
     * @Author: Kai
     * @Date: 2022/2/17 上午 11:47
     */
    @Override
    public List<JsComment> getAllCommentContent(JsComment jsComment) {
        List<JsComment> allCommentContent = commentMapper.getAllCommentContent(jsComment);
        return allCommentContent;
    }

    /* 功能描述: <br>
     * 〈添加一条评论〉
     *
     * @param jsComment
     * @return: java.lang.Boolean
     * @Author: Kai
     * @Date: 2022/2/21 上午 09:13
     */
    @Override
    public Boolean addComment(JsComment jsComment) {
        Boolean addComment = commentMapper.addComment(jsComment);
        return addComment;
    }

    /* 功能描述: <br>
     * 〈根据id获取微圈信息〉
     *
     * @param id
     * @return: com.pro.pojo.JsMicrocircle
     * @Author: Kai
     * @Date: 2022/2/21 上午 11:57
     */
    @Override
    public JsMicrocircle getMicrocircleById(Integer id) {
        JsMicrocircle microcircleById = commentMapper.getMicrocircleById(id);
        return microcircleById;
    }
}
